package io;

import java.io.*;
import java.util.Scanner;

public class PWDemo3_2 {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        File file = null;
        while (true){
            System.out.println("请输入一个文件名:");
            String fileName = sc.nextLine();
            file = new File(fileName);
            if (file.exists()){
                FileInputStream fis = new FileInputStream(file);
                InputStreamReader isr = new InputStreamReader(fis);
                int d;
                while ((d = isr.read())!=-1){
                    System.out.print((char)d);
                }
                break;
            }else {
                System.out.println("没有该文件,请重新输入.");

            }
        }
    }
}
